package com.fsnbigdata.annotation;

/**
 * Created by zq on 2019/4/3.
 */
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import javax.validation.constraints.Pattern;

public class MyConstraintValidator implements ConstraintValidator<MyConstraint, String> {

    private String regexp;


    @Override
    public void initialize(MyConstraint myConstraint) {
        this.regexp = myConstraint.regexp();
    }

    /**
     * @Description: 自定义校验逻辑
     */
    @Override
    public boolean isValid(String string, ConstraintValidatorContext constraintValidatorContext) {

        if(string==null||string.equals("")||string.trim().length()==0){return true;}
        if( string.matches(regexp)){
            return true;
        }
        return false;
    }
}
